package controller;

import model.dto.AddPrescriptionDto;
import model.vo.PrescriptionDrugVo;
import model.dto.PrescriptionDto;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import service.PrescriptionService;
import util.Result;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/pre")
public class PrescriptionController {
    @Resource
    private PrescriptionService service;

    @RequestMapping("/add.do")
    public Object add(@RequestBody List<AddPrescriptionDto> data){
        System.out.println(data);

        int n = service.add(data);
        if(n>0){
            return new Result<>().ok();
        }else{
            return new Result<>().fail();
        }

    }

    @RequestMapping("/findAll.do")
    public Object findAll(PrescriptionDto dto){
        return new Result<>("200","",service.findAll(dto),service.getCount(dto));
    }

    @RequestMapping("/findDrug.do")
    public Object findPrescriptionDrug(Integer id){
        return new Result<>("200","",service.findPrescriptionDrug(id));
    }

    @RequestMapping("/getDrug.do")
    public Object getDrug(@RequestBody List<PrescriptionDrugVo> vo){
        System.out.println(vo);
        return new Result<>("200","",service.getDrug(vo));
    }

}
